package cn.yitun.chat.yitunserverimapicore.business.recent.service.impl;

import cn.yitun.chat.yituncommonutil.YitunMapUtil;
import cn.yitun.chat.yitunservercommonlib.dataentity.dto.userchat.LastChatDto;
import cn.yitun.chat.yitunservercommonlib.dataentity.vo.userchat.LastChatVo;
import cn.yitun.chat.yitunserverimapicore.business.chat.service.LastChatUserService;
import cn.yitun.chat.yitunserverimapicore.business.recent.service.RecentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 最近聊天记录
 * @author yitun
 * @since 1.1
 */
@Service
public class RecentServiceImpl implements RecentService {

    @Resource
    private LastChatUserService lastChatUserService;

    /**
     * 最近聊天 计数
     */
    @Override
    public int lastChatCount(LastChatDto lastChatDto) {
        return lastChatUserService.count(YitunMapUtil.java2Map(lastChatDto, false));
    }

    /**
     * 最近聊天记录 分页
     */
    @Override
    public List<LastChatVo> lastChatList(LastChatDto lastChatDto) {
        return lastChatUserService.listVO(YitunMapUtil.java2Map(lastChatDto, false));
    }

    /**
     * 获取详情
     */
    @Override
    public LastChatVo getById(Long id) {
        return lastChatUserService.getVO(id);
    }

    /**
     * 删除
     */
    @Override
    public void remove(LastChatDto query) {
        lastChatUserService.remove(query.getUserId(), query.getChatId(), query.getType());
    }
}
